//
//  AppTabBarViewController.m
//  opentest
//
//  Created by wuzhx on 2017/12/14.
//  Copyright © 2017年 wuzhx. All rights reserved.
//

#import "AppTabBarViewController.h"
#import "HomeViewController.h"
#import "SearchViewController.h"
#import "MeViewController.h"

@interface AppTabBarViewController ()

@property (strong, nonatomic) UINavigationController *homeNav;
@property (strong, nonatomic) UINavigationController *searchNav;
@property (strong, nonatomic) UINavigationController *meNav;
@property (strong, nonatomic) HomeViewController *homeVC;
@property (strong, nonatomic) SearchViewController *searchVC;
@property (strong, nonatomic) MeViewController *meVC;

@end

@implementation AppTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    self.viewControllers = @[self.homeNav, self.searchNav, self.meNav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - NSObject
- (HomeViewController *)homeVC
{
    if (!_homeVC) {
        _homeVC = [[HomeViewController alloc] init];
        _homeVC.title = @"首页";
    }
    return _homeVC;
}

- (SearchViewController *)searchVC
{
    if (!_searchVC) {
        _searchVC = [[SearchViewController alloc] init];
        _searchVC.title = @"搜索";
    }
    return _searchVC;
}

- (MeViewController *)meVC
{
    if (!_meVC) {
        _meVC = [[MeViewController alloc] init];
        _meVC.title = @"我的";
    }
    return _meVC;
}

- (UINavigationController *)homeNav
{
    if (!_homeNav) {
        _homeNav = [[UINavigationController alloc] initWithRootViewController:self.homeVC];
        _homeNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页"
                                                            image:[UIImage originalImageNamed:@"tabbar_home"]
                                                    selectedImage:[UIImage originalImageNamed:@"tabbar_home_sel"]];
    }
    return _homeNav;
}

- (UINavigationController *)searchNav
{
    if (!_searchNav) {
        _searchNav = [[UINavigationController alloc] initWithRootViewController:self.searchVC];
        _searchNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"搜索"
                                                              image:[UIImage originalImageNamed:@"tabbar_search"]
                                                      selectedImage:[UIImage originalImageNamed:@"tabbar_search_sel"]];
    }
    return _searchNav;
}

- (UINavigationController *)meNav
{
    if (!_meNav) {
        _meNav = [[UINavigationController alloc] initWithRootViewController:self.meVC];
        _meNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的"
                                                          image:[UIImage originalImageNamed:@"tabbar_me"]
                                                  selectedImage:[UIImage originalImageNamed:@"tabbar_me_sel"]];
    }
    return _meNav;
}

@end
